package lxh.com.union.frame.mvp;

import java.lang.ref.WeakReference;

/**
 * Created by Administrator on 2017/7/4.
 */

public abstract class BasePresent<V extends IBaseView> {

    private WeakReference<V> mWeakReference;

    /**
     * 关联view
     * @param v
     */
    public void attach(V v){
        mWeakReference=new WeakReference<V>(v);

    }


    /**
     * 分离view
     * @param v
     */
    public void detach(V v){
        if (mWeakReference!=null){
            mWeakReference.clear();
            mWeakReference=null;
        }
    }

    /**
     * 获取view
     * @return
     */
    public V getView(){
        if (mWeakReference!=null){
            return mWeakReference.get();
        }
        return null;
    }
}
